package com.example.himalayaproject.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.himalayaproject.R;
import com.example.himalayaproject.adapter.FindViewpagerAdapter;
import com.example.himalayaproject.find.anchor.fragment.AnchorFragment;
import com.example.himalayaproject.find.broadcast.fragment.BroadcastFragment;
import com.example.himalayaproject.find.fenlei.fragment.FenLei_Fragment;
import com.example.himalayaproject.find.monthlyfocus.fragment.Monthly_Focus_Fragment;
import com.example.himalayaproject.find.recommend.fragment.RecommendFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class FindFragment extends Fragment {


    public FindFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_find, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        aboutTableLayout(view);
    }

    private void aboutTableLayout(View view) {
        TabLayout tabLayout = (TabLayout) view.findViewById(R.id.main_tablayout);
        ViewPager viewpager= (ViewPager) view.findViewById(R.id.main_viewpager);
        List<String>  list = new ArrayList<>();
         list.add("推荐");
         list.add("分类");
         list.add("广播");
         list.add("榜单");
         list.add("主播");
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new RecommendFragment());
        fragments.add(new FenLei_Fragment());
        fragments.add(new BroadcastFragment());
        fragments.add(new Monthly_Focus_Fragment());
        fragments.add(new AnchorFragment());
        FindViewpagerAdapter adapter = new FindViewpagerAdapter(getChildFragmentManager(),list,fragments);
        viewpager.setOffscreenPageLimit(5);
        viewpager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewpager);
    }
}
